Implement unified error handling for Python inline code on left-hand side of colon #474
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Previously, Python inline code on the left-hand side of colons (key positions) produced different, confusing error messages depending on the specific syntax used. The following examples all caused different errors:
This created a poor user experience with inconsistent and sometimes misleading error messages.
Solution
Implemented early detection of Python inline code patterns (
<<...>>) in key positions with a unified error message: "Python inline code on the left-hand side of the colon is generally not allowed."The validation occurs in the
jsonLoads()method before existing parsing logic, ensuring consistent error handling across all scenarios where Python inline code appears in key positions.Changes
CJsonPreprocessor.pyat line ~2153<<...>>patterns before colons in key-value pairsTesting
All problematic cases now show appropriate rejection:
"key" : <<expression>>)Impact
This change implements the design philosophy that Python inline code should be restricted to value positions (right-hand side) and not used for dynamic key generation.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.